首页新效果

chengzhenyu 8 年之前
父节点
当前提交
2375da4166

+ 166 - 0
app/src/main/java/ai/pai/client/adapter/NewRecentPhotoStaggeredAdapter.java

@@ -0,0 +1,166 @@
1
+package ai.pai.client.adapter;
2
+
3
+import android.content.Context;
4
+import android.content.Intent;
5
+import android.support.v7.widget.RecyclerView;
6
+import android.view.LayoutInflater;
7
+import android.view.View;
8
+import android.view.ViewGroup;
9
+import android.widget.ImageView;
10
+import android.widget.TextView;
11
+
12
+import com.android.common.utils.DeviceUtils;
13
+import com.android.common.utils.TimeUtils;
14
+import com.android.views.circleimageview.CircleImageView;
15
+import com.nostra13.universalimageloader.core.DisplayImageOptions;
16
+import com.umeng.analytics.MobclickAgent;
17
+
18
+import java.util.ArrayList;
19
+
20
+import ai.pai.client.R;
21
+import ai.pai.client.activity.GroupActivity;
22
+import ai.pai.client.activity.PhotoDetailsActivity;
23
+import ai.pai.client.beans.GroupInfo;
24
+import ai.pai.client.beans.GroupPhotoItem;
25
+import ai.pai.client.utils.GroupCreateUtils;
26
+import ai.pai.client.utils.PhotoLoader;
27
+import ai.pai.client.utils.UmengEvent;
28
+
29
+public class NewRecentPhotoStaggeredAdapter extends RecyclerView.Adapter<NewRecentPhotoStaggeredAdapter.MyViewHolder> {
30
+
31
+    private Context context;
32
+    private LayoutInflater mInflater;
33
+    private DisplayImageOptions options;
34
+    private ArrayList<GroupPhotoItem> photoList;
35
+    private int width;
36
+
37
+    public NewRecentPhotoStaggeredAdapter(Context context, ArrayList<GroupPhotoItem> photoList){
38
+        this.context = context;
39
+        this.photoList = photoList;
40
+        width = DeviceUtils.getScreenWidth(this.context)/2;
41
+        mInflater = LayoutInflater.from(this.context);
42
+        options = PhotoLoader.getPhotoOptions();
43
+    }
44
+
45
+    public synchronized void clearPhotoList(){
46
+        photoList.clear();
47
+        notifyDataSetChanged();
48
+    }
49
+
50
+    public synchronized void addPhotoList(ArrayList<GroupPhotoItem> photoList){
51
+        int startPosition = this.photoList.size();
52
+        this.photoList.addAll(photoList);
53
+        if(startPosition==0){
54
+            notifyDataSetChanged();
55
+        }else{
56
+            notifyItemRangeInserted(startPosition,photoList.size());
57
+        }
58
+    }
59
+
60
+    public ArrayList<GroupPhotoItem> getPhotoList(){
61
+        return photoList;
62
+    }
63
+
64
+    @Override
65
+    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
66
+        View view = mInflater.inflate(R.layout.new_stagger_recent_photo_item_view,parent,false);
67
+        MyViewHolder viewHolder = new MyViewHolder(view);
68
+        viewHolder.photo = (ImageView)view.findViewById(R.id.iv_stagger_photo);
69
+        viewHolder.avatar = (CircleImageView)view.findViewById(R.id.iv_stagger_avatar);
70
+        viewHolder.commentCount = (TextView)view.findViewById(R.id.tv_stagger_comment_count);
71
+        viewHolder.name = (TextView)view.findViewById(R.id.tv_stagger_name);
72
+        viewHolder.thumbUpCount = (TextView)view.findViewById(R.id.tv_stagger_like_count);
73
+        viewHolder.time = (TextView)view.findViewById(R.id.tv_stagger_time);
74
+        viewHolder.headLayout = view.findViewById(R.id.layout_stagger_header);
75
+        viewHolder.maskView = view.findViewById(R.id.layout_image_mask);
76
+        viewHolder.groupPhotoCount = (TextView) view.findViewById(R.id.tv_group_photo_count);
77
+        return viewHolder;
78
+    }
79
+
80
+    @Override
81
+    public void onBindViewHolder(MyViewHolder holder, int position) {
82
+        final GroupPhotoItem item = photoList.get(position);
83
+        int height ;
84
+        if(item.thumbnailWidth>0){
85
+            height =item.thumbnailHeight *width/item.thumbnailWidth;
86
+        }else{
87
+            height = width*16/10;
88
+        }
89
+        ViewGroup.LayoutParams lp=holder.photo.getLayoutParams();
90
+        lp.height = height;
91
+        holder.photo.setLayoutParams(lp);
92
+        holder.photo.setOnClickListener(new View.OnClickListener(){
93
+            @Override
94
+            public void onClick(View v) {
95
+                Intent intent = new Intent(context, PhotoDetailsActivity.class);
96
+                intent.putExtra("list",photoList);
97
+                intent.putExtra("photo_item",item);
98
+                context.startActivity(intent);
99
+                MobclickAgent.onEvent(context, UmengEvent.home_item_photo_click);
100
+            }
101
+        });
102
+        holder.headLayout.setOnClickListener(new View.OnClickListener(){
103
+            @Override
104
+            public void onClick(View v) {
105
+                Intent intent = new Intent(context, GroupActivity.class);
106
+                GroupInfo info = new GroupInfo();
107
+                info.groupId = item.groupId;
108
+                info.groupName = item.groupName;
109
+                info.groupAvatarId = item.groupDefaultAvatar;
110
+                intent.putExtra("group",info);
111
+                context.startActivity(intent);
112
+                MobclickAgent.onEvent(context, UmengEvent.home_item_group_header_click);
113
+            }
114
+        });
115
+        PhotoLoader.getInstance(context).displayImage(item.thumbnailUrl,holder.photo,options);
116
+        if(item.groupDefaultAvatar>=0){
117
+            holder.avatar.setImageResource(GroupCreateUtils.getDrawableIdForAvatar(item.groupDefaultAvatar));
118
+        }else{
119
+            PhotoLoader.getInstance(context).displayImage(item.groupAvatar,holder.avatar,options);
120
+        }
121
+        holder.name.setText(item.groupName);
122
+        holder.time.setText(TimeUtils.getFormattedTime(item.captureTime));
123
+        holder.thumbUpCount.setText(String.valueOf(item.thumbupNum));
124
+        holder.commentCount.setText(String.valueOf(item.commentNum));
125
+        holder.headLayout.setVisibility(View.VISIBLE);
126
+        holder.maskView.setVisibility(View.GONE);
127
+
128
+        if(position>0){
129
+            GroupPhotoItem lastPhoto = photoList.get(position-1);
130
+            if(lastPhoto.groupId.equals(item.groupId)){
131
+                holder.headLayout.setVisibility(View.GONE);
132
+            }
133
+        }
134
+        if(position<photoList.size()-1){
135
+            GroupPhotoItem nextPhoto = photoList.get(position+1);
136
+            if(!nextPhoto.groupId.equals(item.groupId)){
137
+                holder.maskView.setVisibility(View.VISIBLE);
138
+                holder.groupPhotoCount.setText("10");
139
+            }
140
+        }
141
+
142
+    }
143
+
144
+    @Override
145
+    public int getItemCount() {
146
+        return photoList.size();
147
+    }
148
+
149
+    class MyViewHolder extends RecyclerView.ViewHolder{
150
+
151
+        private ImageView photo;
152
+        private CircleImageView avatar;
153
+        private TextView name;
154
+        private TextView time;
155
+        private TextView thumbUpCount;
156
+        private TextView commentCount;
157
+        private View headLayout;
158
+        private View maskView;
159
+        private TextView groupPhotoCount;
160
+
161
+        public MyViewHolder(View view){
162
+            super(view);
163
+        }
164
+    }
165
+}
166
+

+ 3 - 2
app/src/main/java/ai/pai/client/fragments/TabRecentPhotoFragment.java

@@ -40,6 +40,7 @@ import java.util.HashMap;
40 40
 
41 41
 import ai.pai.client.R;
42 42
 import ai.pai.client.activity.MainActivity;
43
+import ai.pai.client.adapter.NewRecentPhotoStaggeredAdapter;
43 44
 import ai.pai.client.adapter.RecentPhotoStaggeredAdapter;
44 45
 import ai.pai.client.beans.GroupPhotoItem;
45 46
 import ai.pai.client.db.DBService;
@@ -54,7 +55,7 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh
54 55
 
55 56
     private RecyclerView recyclerView;
56 57
     private SwipeRefreshLayout swipeRefreshLayout;
57
-    private RecentPhotoStaggeredAdapter refreshAdapter;
58
+    private NewRecentPhotoStaggeredAdapter refreshAdapter;
58 59
     private HeaderAndFooterRecyclerViewAdapter photoAdapter;
59 60
     private EndlessRecyclerOnScrollListener scrollListener;
60 61
     private View loadMoreView;
@@ -94,7 +95,7 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh
94 95
         }else{
95 96
             photoList = DBService.getInstance(getActivity()).getRecentPhotos();
96 97
         }
97
-        refreshAdapter = new RecentPhotoStaggeredAdapter(getActivity(), photoList);
98
+        refreshAdapter = new NewRecentPhotoStaggeredAdapter(getActivity(), photoList);
98 99
         photoAdapter = new HeaderAndFooterRecyclerViewAdapter(refreshAdapter);
99 100
         recyclerView.setAdapter(photoAdapter);
100 101
         loadMoreView = LayoutInflater .from(getActivity()).inflate(R.layout.view_load_more, recyclerView, false);

二进制
app/src/main/res/drawable-xhdpi/plus.png


+ 118 - 0
app/src/main/res/layout/new_stagger_recent_photo_item_view.xml

@@ -0,0 +1,118 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:app="http://schemas.android.com/apk/res-auto"
4
+    android:layout_width="match_parent"
5
+    android:layout_height="wrap_content"
6
+    android:layout_margin="3dp"
7
+    android:background="@color/white">
8
+
9
+    <ImageView
10
+        android:id="@+id/iv_stagger_photo"
11
+        android:layout_width="wrap_content"
12
+        android:layout_height="wrap_content"
13
+        android:scaleType="centerCrop" />
14
+
15
+    <RelativeLayout
16
+        android:id="@+id/layout_image_mask"
17
+        android:layout_width="match_parent"
18
+        android:layout_height="wrap_content"
19
+        android:layout_alignTop="@id/iv_stagger_photo"
20
+        android:layout_alignBottom="@id/iv_stagger_photo"
21
+        android:background="@color/half_transparent" >
22
+
23
+        <TextView
24
+            android:id="@+id/tv_group_photo_count"
25
+            android:layout_width="wrap_content"
26
+            android:layout_height="wrap_content"
27
+            android:textColor="@color/white"
28
+            android:textSize="32sp"
29
+            android:drawableLeft="@drawable/plus"
30
+            android:drawablePadding="5dp"
31
+            android:layout_centerInParent="true" />
32
+
33
+    </RelativeLayout>
34
+
35
+    <RelativeLayout
36
+        android:id="@+id/layout_stagger_header"
37
+        android:layout_width="match_parent"
38
+        android:layout_height="40dp"
39
+        android:layout_alignParentTop="true"
40
+        android:background="@color/half_transparent"
41
+        android:gravity="center_vertical">
42
+
43
+        <com.android.views.circleimageview.CircleImageView
44
+            android:id="@+id/iv_stagger_avatar"
45
+            android:layout_width="28dp"
46
+            android:layout_height="28dp"
47
+            android:layout_marginLeft="6dp"
48
+            android:layout_marginTop="6dp"
49
+            android:src="@drawable/default_avatar"
50
+            app:civ_border_color="@color/pop_bg_color"
51
+            app:civ_border_width="1dp" />
52
+
53
+        <TextView
54
+            android:id="@+id/tv_stagger_name"
55
+            android:layout_width="wrap_content"
56
+            android:layout_height="wrap_content"
57
+            android:layout_marginLeft="6dp"
58
+            android:layout_marginTop="4dp"
59
+            android:layout_toRightOf="@id/iv_stagger_avatar"
60
+            android:singleLine="true"
61
+            android:textColor="@color/white"
62
+            android:textSize="12sp" />
63
+
64
+        <TextView
65
+            android:id="@+id/tv_stagger_time"
66
+            android:layout_width="wrap_content"
67
+            android:layout_height="wrap_content"
68
+            android:layout_alignParentBottom="true"
69
+            android:layout_marginBottom="5dp"
70
+            android:layout_marginLeft="6dp"
71
+            android:layout_toRightOf="@id/iv_stagger_avatar"
72
+            android:textColor="@color/white"
73
+            android:textSize="9sp" />
74
+    </RelativeLayout>
75
+
76
+    <RelativeLayout
77
+        android:layout_width="match_parent"
78
+        android:layout_height="30dp"
79
+        android:layout_alignParentBottom="true"
80
+        android:background="@color/half_transparent"
81
+        android:gravity="center_vertical">
82
+
83
+        <ImageView
84
+            android:id="@+id/iv_stagger_like"
85
+            android:layout_width="12dp"
86
+            android:layout_height="12dp"
87
+            android:layout_marginLeft="8dp"
88
+            android:src="@drawable/thumbup" />
89
+
90
+        <TextView
91
+            android:id="@+id/tv_stagger_like_count"
92
+            android:layout_width="wrap_content"
93
+            android:layout_height="wrap_content"
94
+            android:layout_marginLeft="4dp"
95
+            android:layout_toRightOf="@id/iv_stagger_like"
96
+            android:textColor="@color/white"
97
+            android:textSize="10sp" />
98
+
99
+        <ImageView
100
+            android:id="@+id/iv_stagger_comment"
101
+            android:layout_width="12dp"
102
+            android:layout_height="12dp"
103
+            android:layout_marginLeft="10dp"
104
+            android:layout_toRightOf="@id/tv_stagger_like_count"
105
+            android:src="@drawable/comment" />
106
+
107
+        <TextView
108
+            android:id="@+id/tv_stagger_comment_count"
109
+            android:layout_width="wrap_content"
110
+            android:layout_height="wrap_content"
111
+            android:layout_marginLeft="4dp"
112
+            android:layout_toRightOf="@id/iv_stagger_comment"
113
+            android:textColor="@color/white"
114
+            android:textSize="10sp" />
115
+
116
+    </RelativeLayout>
117
+
118
+</RelativeLayout>

+ 1 - 0
app/src/main/res/values/colors.xml

@@ -5,6 +5,7 @@
5 5
     <color name="colorAccent">#FF4081</color>
6 6
 
7 7
     <color name="transparent">#00000000</color>
8
+    <color name="half_transparent">#60000000</color>
8 9
     <color name="white">#ffffffff</color>
9 10
     <color name="black">#ff000000</color>
10 11